package com.atgm.mall.gmmailcoupon.controller;

import com.atgm.common.utils.PageUtils;
import com.atgm.common.utils.R;
import com.atgm.mall.gmmailcoupon.entity.GameGoodsSaleEntity;
import com.atgm.mall.gmmailcoupon.service.GoodsSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 游戏商品优惠
 */
@RestController
@RequestMapping("/gmmallcoupon/goodssale")
public class GameGoodsSaleController {

    @Autowired

    private GoodsSaleService goodsSaleService;

    /**
     * 首页获取优惠商品
     * @return
     */
    @GetMapping("/list")
    public R getGoodsSaleList(@RequestParam Map<String, Object> params) {
        PageUtils page = goodsSaleService.queryPage(params);
        return R.ok().setData(page);
    }

    /**
     * 查询优惠商品信息
     */
    @GetMapping("/info")
    public R getGoodsSale(@RequestParam("ids") List<Long> goodsIds) {
        List<GameGoodsSaleEntity> list = goodsSaleService.queryInfoByCatIds(goodsIds);
        return R.ok().setData(list);
    }

    @GetMapping("/couponInfo/{id}")
    public R getGoodsSaleInfoByGoodsId(@PathVariable("id") Long goodsId) {
        GameGoodsSaleEntity entity = goodsSaleService.queryGoodsSaleInfoByGoodsId(goodsId);
        return R.ok().setData(entity);
    }

    /**
     * 获取折扣中的游戏id
     */
    @GetMapping("/gameIds")
    public R getSaleGameIds(@RequestParam Map<String, Object> params) {
        List<Long> list = goodsSaleService.querySaleGameIds(params);
        return R.ok().setData(list);
    }

}
